# Maintainer: Saul Ibarra Corretge <saghul@gmail.com>
# Contributor: Alexey Pavlov <alexpux@gmail.com>

_realname=pyqt-builder
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.15.2
pkgrel=1
pkgdesc="The PEP 517 compliant PyQt build system (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('spdx:GPL-2.0-or-later OR spdx:GPL-3.0-or-later')
url="https://www.riverbankcomputing.com/software/pyqt-builder"
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-packaging"
         "${MINGW_PACKAGE_PREFIX}-sip")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-wheel")
options=(!strip)
source=("https://pypi.io/packages/source/P/PyQt-builder/PyQt-builder-${pkgver}.tar.gz"
        001-mingw-python.patch)
sha256sums=('746cfe83c03ebff4458d478a1c06714790ef93e458ecd5a28bc2837bac88eb74'
            'a0127037669e99008bf463750a6bd45d8cc4d16392566d28dc7b2b9e42833c4a')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}/001-mingw-python.patch"

  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd python-build-${MSYSTEM}

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}"/python-build-${MSYSTEM}
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  # Delete bundled MSVC DLLs
  rm -rf "${pkgdir}"/${MINGW_PREFIX}/lib/python*/site-packages/pyqtbuild/bundle/dlls

  install -D -m644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
